import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/widgets.dart';

import 'effect.dart';
import 'list/component.dart';
import 'list/state.dart';
import 'reducer.dart';
import 'state.dart';
import 'view.dart';

class TickerSubjectComponentState extends ComponentState<SubjectTabState>
    with SingleTickerProviderStateMixin {}

class SubjectTabComponent extends Component<SubjectTabState> {
  SubjectTabComponent()
      : super(
          effect: buildEffect(),
          reducer: buildReducer(),
          view: buildView,
          dependencies: Dependencies<SubjectTabState>(
              slots: <String, Dependent<SubjectTabState>>{
                'public': SubjectPublicConnector() + SubjectListComponent(),
                'private': SubjectPrivateConnector() + SubjectListComponent(),
              }),
        );

  // for TabController
  @override
  TickerSubjectComponentState createState() => TickerSubjectComponentState();
}

class SubjectPublicConnector extends ConnOp<SubjectTabState, SubjectListState> {
  @override
  SubjectListState get(SubjectTabState state) {
    return state.publicState;
  }

  @override
  void set(SubjectTabState state, SubjectListState subState) {
    state.publicState = subState;
  }
}

class SubjectPrivateConnector
    extends ConnOp<SubjectTabState, SubjectListState> {
  @override
  SubjectListState get(SubjectTabState state) {
    return state.privateState;
  }

  @override
  void set(SubjectTabState state, SubjectListState subState) {
    state.privateState = subState;
  }
}
